package com.itheima.controller;

import com.itheima.project.costomannotation.log ;
import com.itheima.project.*;
import com.itheima.project.emp.Emp;
import com.itheima.project.emp.EmpQueryParam;
import com.itheima.filter.service.impl.EmpServiceIml;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
    @Resource
    private EmpServiceIml empServiceIml;

    @GetMapping
    public Result page(EmpQueryParam eqp) {
        log.info("查询请求参数： {}",eqp.toString());
        PageBean pageBean = empServiceIml.page(eqp);  //empService.page(page, pageSize);
        return Result.success(pageBean);
    }
    @log
    @PostMapping
    public Result saveEmp(@RequestBody Emp emp){
        log.info(emp.toString());
        empServiceIml.saveEmp(emp);
        return Result.success();
    }
    @DeleteMapping
    public Result deletById(@RequestParam List<Integer> ids){
        log.info(ids.toString());
        empServiceIml.deletById(ids);
        return Result.success();

    }



    @GetMapping("/{id}")
    public Result queryEmpById(@PathVariable Integer id){

        Emp emp = empServiceIml.getInfo(id);
        return Result.success(emp);
    }
    @log
    @PutMapping
    public Result modifyEmp(@RequestBody Emp emp){

        empServiceIml.modifyEmp(emp);
        return Result.success();
    }
    @GetMapping("list")
    public Result queryAllEmp(){
        log.info("所有员工查询");
        List list = empServiceIml.queryAllEmp();
        return Result.success(list);
    }
    @log
    @PutMapping("/changePassword")
    public Result changePassword(@RequestBody Password password){

        empServiceIml.changePassword(password);
        return Result.success();
    }

}